package com.fastloan.mgt.application.contract.service.impl.contractmode.mode;

import com.fastloan.mgt.application.base.enums.ApplicationStatusEnum;
import com.fastloan.mgt.application.base.model.Application;
import com.fastloan.mgt.application.base.model.ApplicationVo;
import com.fastloan.mgt.application.contract.model.ApplicationContract;
import com.fastloan.mgt.application.contract.service.impl.contractmode.ContractMode;
import com.fastloan.mgt.product.basics.model.Product;
import com.fastloan.mgt.product.enums.ProductType;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 消费类自动签约
 *
 * @author yanwe
 * createTime 2018-01-2018/1/7 13:12
 */
@Component
public class AutoContract extends ContractMode {

    @Override
    public void contract(Application application, Product product) {
        String applicationId = application.getApplicationId();
        ApplicationVo applicationVo = applicationContractService.getApplicationVo(applicationId);
        ApplicationContract applicationContract = new ApplicationContract();
        applicationContract.setApplicationId(applicationId);
        applicationContract.setContractTime(new Date());
        applicationContract.setLoanTime(new Date());
        applicationContract.setLoanAmount(applicationVo.getLoanAmount());
        applicationContract.setCreditPeriod(applicationVo.getApplyPeriod());
        applicationContract.setLoanMonthRate(product.getMonthlyLimit());//TODO:贷款月利率自动签约无法获得,暂取产品最高月利率
        applicationContractService.contract(applicationContract,null);
        applicationService.modifyApplicationStatus(applicationId, ApplicationStatusEnum.WAIT_CUSTOMER_SIGNED);
    }

    @Override
    public Integer contractType() {
        return ProductType.CON_SIM.getType();
    }
}
